<?php

/**
 * reportdef filter form base class.
 *
 * @package    e-DSL
 * @subpackage filter
 * @author     Your name here
 * @version    SVN: $Id: sfDoctrineFormFilterGeneratedTemplate.php 29570 2010-05-21 14:49:47Z Kris.Wallsmith $
 */
abstract class BasereportdefFormFilter extends BaseFormFilterDoctrine
{
  public function setup()
  {
    $this->setWidgets(array(
      'code'         => new sfWidgetFormFilterInput(),
      'title'        => new sfWidgetFormFilterInput(),
      'section'      => new sfWidgetFormFilterInput(),
      'type'         => new sfWidgetFormFilterInput(),
      'description'  => new sfWidgetFormFilterInput(),
      'commentaire'  => new sfWidgetFormFilterInput(),
      'fichier'      => new sfWidgetFormFilterInput(),
      'module'       => new sfWidgetFormFilterInput(),
      'action'       => new sfWidgetFormFilterInput(),
      'preExecution' => new sfWidgetFormFilterInput(),
      'javascript'   => new sfWidgetFormFilterInput(),
      'public'       => new sfWidgetFormChoice(array('choices' => array('' => 'yes or no', 1 => 'yes', 0 => 'no'))),
      'hidden'       => new sfWidgetFormChoice(array('choices' => array('' => 'yes or no', 1 => 'yes', 0 => 'no'))),
      'created_at'   => new sfWidgetFormFilterDate(array('from_date' => new sfWidgetFormDate(), 'to_date' => new sfWidgetFormDate(), 'with_empty' => false)),
      'updated_at'   => new sfWidgetFormFilterDate(array('from_date' => new sfWidgetFormDate(), 'to_date' => new sfWidgetFormDate(), 'with_empty' => false)),
      'roles_list'   => new sfWidgetFormDoctrineChoice(array('multiple' => true, 'model' => 'role')),
    ));

    $this->setValidators(array(
      'code'         => new sfValidatorPass(array('required' => false)),
      'title'        => new sfValidatorPass(array('required' => false)),
      'section'      => new sfValidatorPass(array('required' => false)),
      'type'         => new sfValidatorPass(array('required' => false)),
      'description'  => new sfValidatorPass(array('required' => false)),
      'commentaire'  => new sfValidatorPass(array('required' => false)),
      'fichier'      => new sfValidatorPass(array('required' => false)),
      'module'       => new sfValidatorPass(array('required' => false)),
      'action'       => new sfValidatorPass(array('required' => false)),
      'preExecution' => new sfValidatorPass(array('required' => false)),
      'javascript'   => new sfValidatorPass(array('required' => false)),
      'public'       => new sfValidatorChoice(array('required' => false, 'choices' => array('', 1, 0))),
      'hidden'       => new sfValidatorChoice(array('required' => false, 'choices' => array('', 1, 0))),
      'created_at'   => new sfValidatorDateRange(array('required' => false, 'from_date' => new sfValidatorDateTime(array('required' => false, 'datetime_output' => 'Y-m-d 00:00:00')), 'to_date' => new sfValidatorDateTime(array('required' => false, 'datetime_output' => 'Y-m-d 23:59:59')))),
      'updated_at'   => new sfValidatorDateRange(array('required' => false, 'from_date' => new sfValidatorDateTime(array('required' => false, 'datetime_output' => 'Y-m-d 00:00:00')), 'to_date' => new sfValidatorDateTime(array('required' => false, 'datetime_output' => 'Y-m-d 23:59:59')))),
      'roles_list'   => new sfValidatorDoctrineChoice(array('multiple' => true, 'model' => 'role', 'required' => false)),
    ));

    $this->widgetSchema->setNameFormat('reportdef_filters[%s]');

    $this->errorSchema = new sfValidatorErrorSchema($this->validatorSchema);

    $this->setupInheritance();

    parent::setup();
  }

  public function addRolesListColumnQuery(Doctrine_Query $query, $field, $values)
  {
    if (!is_array($values))
    {
      $values = array($values);
    }

    if (!count($values))
    {
      return;
    }

    $query
      ->leftJoin($query->getRootAlias().'.reportrole reportrole')
      ->andWhereIn('reportrole.role_id', $values)
    ;
  }

  public function getModelName()
  {
    return 'reportdef';
  }

  public function getFields()
  {
    return array(
      'id'           => 'Number',
      'code'         => 'Text',
      'title'        => 'Text',
      'section'      => 'Text',
      'type'         => 'Text',
      'description'  => 'Text',
      'commentaire'  => 'Text',
      'fichier'      => 'Text',
      'module'       => 'Text',
      'action'       => 'Text',
      'preExecution' => 'Text',
      'javascript'   => 'Text',
      'public'       => 'Boolean',
      'hidden'       => 'Boolean',
      'created_at'   => 'Date',
      'updated_at'   => 'Date',
      'roles_list'   => 'ManyKey',
    );
  }
}
